﻿function LoadCategoryDropDown() {
    categoryCount = 1;
    var listCityJson;
    var s = $("<select 'id=ddlCategory' />");
    $.ajax({
        type: "POST",
        url: "HandlerSearchCV.ashx",
        data: { 'search': 'category' },
        dataType: "json",
        success: function (responseData, status, xhr) {
            listCityJson = responseData;
            $.each(responseData, function (i, item) {
                s.append($("<option></option>").val(i).html(responseData[i]));

            });

        },
        error: function (responseData, status, xhr) {
            alert(responseData.toString());
        }
    });

    s.appendTo('#CategoryLoc');
    $('#CategoryLoc').append("<br />");

    $("button[id^='categoryAdd']").live("click", null, function () {
        categoryCount++;
        var ddlDiv = $("<div id='ddlDiv'></div>")
        var select = $("<select 'id=ddlCategory'" + categoryCount + " />");
        $.each(listCityJson, function (i, item) {
            select.append($("<option></option>").val(i).html(listCityJson[i]));
        });

        select.appendTo(ddlDiv)
        var btnDelCat = "btnDelCat" + categoryCount;
        ddlDiv.append("<button id='" + btnDelCat + "' class=\"buttonDel\" >X</button>");
        ddlDiv.appendTo('#CategoryLoc');
        return false;
    })

    $("button[id^='btnDelCat']").live("click", null, function () {
        var select = $(this).parent();
        select.remove();

        return false;
    });
}